﻿using System;
using System.ComponentModel;

namespace Heimdallr
{
    /// <summary>
    /// Provides data for the <see cref="ServiceElement.StatusChanged"/> event.
    /// </summary>
    public class StatusChangedEventArgs : EventArgs
    {
        #region Field

        private ServiceElementStatus oldStatus;
        private ServiceElementStatus newStatus;

        #endregion

        #region Property

        /// <summary>
        /// Get the previous status of current element.
        /// </summary>
        public ServiceElementStatus OldStatus
        {
            get { return this.oldStatus; }
        }

        /// <summary>
        /// Get the latest status of current element.
        /// </summary>
        public ServiceElementStatus NewStatus
        {
            get { return this.newStatus; }
        }

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the StatusChangedEventArgs class.
        /// </summary>
        /// <param name="oldStatus">The previous status of current element.</param>
        /// <param name="newStatus">The latest status of current element.</param>
        /// <exception cref="InvalidEnumArgumentException">Parameter <paramref name="oldStatus"/> or <paramref name="newStatus"/> is not a valid value.</exception>
        public StatusChangedEventArgs(ServiceElementStatus oldStatus, ServiceElementStatus newStatus)
        {
            if (!Enum.IsDefined(typeof(ServiceElementStatus), oldStatus))
                throw new InvalidEnumArgumentException("oldStatus", (int)oldStatus, typeof(ServiceElementStatus));

            if (!Enum.IsDefined(typeof(ServiceElementStatus), newStatus))
                throw new InvalidEnumArgumentException("newStatus", (int)newStatus, typeof(ServiceElementStatus));

            this.oldStatus = oldStatus;
            this.newStatus = newStatus;
        }

        #endregion
    }
}
